package com.dialogactivity.qingyuan;


import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void Dialog(View v){
        final AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setTitle("提示对话框");
        builder.setIcon(R.mipmap.ic_launcher);
        builder.setMessage("是否关闭对话框");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                onDestroy();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                AlertDialog dialog=builder.create();
                dialog.show();
            }
        });
        builder.create().show();
    }
    public void proDialog(View v){
        final ProgressDialog dialog=new ProgressDialog(this);
        dialog.setTitle("正在加载。。。。");
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setMax(100);
        dialog.show();
        new Thread(){
            public void run(){
                for(int i=0;i<=100;i++){
                    dialog.setProgress(i);
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                dialog.dismiss();
            }
        }.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
